﻿using System;
using System.Data.Linq;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using EqRepair.Code.Classes;
using EqRepair.Code.Data;
using EqRepair.Code.Enums;

namespace EqRepair.Web
{
	public partial class Site1 : MasterPage
	{
		public EmployeeRole? WhoCanViewPage { get; set; }

		protected void Page_Load(object sender, EventArgs e)
		{
			bool IsLog = new SessionAuthentification(Session).IsUserLogIn();

			//pnlAccessDenied.Visible = !(pnlMainContent.Visible = Session.GetCurrentUserRole() == WhoCanViewPage);
			if (new SessionAuthentification(Session).GetCurrentUserRole() > 0)
			{
				pnlLogin.Visible = false;
				pnlMainContent.Visible = Helper.IsAccesToViewUrl(new SessionAuthentification(Session).GetCurrentUserRole(), Request.RawUrl);
				pnlAccessDenied.Visible = !Helper.IsAccesToViewUrl(new SessionAuthentification(Session).GetCurrentUserRole(), Request.RawUrl); 
			}
			else
			{
				pnlMainContent.Visible = false;
				pnlLogin.Visible = true;
				pnlAccessDenied.Visible = true;
			}

#pragma warning disable 665
			if(IsLog)
			{
				pnlHello.Visible = true;
				lblHello.Text = new SessionAuthentification(Session).GetCurrentUserFullName();
			}
#pragma warning restore 665
		}

		protected void btnLogin_Click(object sender, EventArgs e)
		{
			new SessionAuthentification(Session).LogIn(txtLogin.Text, txtPassword.Text);
			Response.Redirect(Request.RawUrl);
		}

		protected void BtnExit_Click(object sender, EventArgs e)
		{
			new SessionAuthentification(Session).LogOut();
			Response.Redirect(Request.RawUrl);
		}
	}
}
